<?php
include '../Huvudmeny/index.php';
include '../phpFunctions/databaseConnect.php';

session_start();
$myusername= (isset($_GET['profileName']))?$_GET['profileName']:0;
$currentPage = (isset($_GET['currentPage']))?$_GET['currentPage']:0;//To make it possible to scroll through items
$result = mysql_query("select username, fornamn, efternamn, email, lan, stad, profilepictureURL, telefonnummer from users where username ='$myusername'");
 while($row = mysql_fetch_assoc($result)) {
	
        $fornamn= $row["fornamn"];
	$efternamn= $row["efternamn"];
        $email = $row["email"];
        $lan = $row["lan"];
        $stad = $row["stad"];
        $profilepicture= $row["profilepictureURL"];
        $telefon= $row["telefonnummer"];
        }
 $result = mysql_query("select pictureURL from items,users where username='$myusername' and user=user_id");
                 $i=0;
                 while($row = mysql_fetch_assoc($result))  {
                        $pictureURL = $row["pictureURL"];
                        $pictureURLArray[$i] = $pictureURL;
                        ++$i;
                        }
$result = mysql_query("select item_id from items i, users u where i.user=u.user_id and u.username= '$myusername'  order by item_id");
                 $i=0;
                 while($row = mysql_fetch_assoc($result))  {
                        $itemID = $row["item_id"];
                        $itemIdArray[$i] = $itemID;
                        ++$i;
                        }

mysql_close();
include '../phpFunctions/imageResize.php';
$imageSize = getimagesize("../Images/profilePictures/$profilepicture");
$newSize = imageResize($imageSize[0],$imageSize[1],200);
$newSizearray = imageResizeVector($imageSize[0], $imageSize[1], 200);
$newSizearray0 = $newSizearray[0] + 22;//Ugly solution to make the frame around the picture adapt to the picturesize
$newSizearray1 = $newSizearray[1] + 28;

include '../phpFunctions/picIndexArray.php';
$showPhone = getUserInfo($myusername, 'showPhone');
$showEmail = getUserInfo($myusername, 'showEmail');

?>













<html>
<head>
<link href="../getProfile/profile.css" media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript">

function displayDate()
{
document.getElementById("demo").innerHTML=("<form id='sendmail' action='../getProfile/sendMailToUserAction.php' onsubmit='return validateForm()' enctype='multipart/form-data' method='post'>\n\Din mail-adress:<br> <input type='text' name='email'<br><br>Namn:<br> <input type='text'  name='namn'><br>\n\Angående:<br> <input type='text' name='angaende' SIZE=25 value='Ang. annons || dinkonst.se'><br>Meddelande: <br><textarea name='meddelande' rows='5' cols='30' >Skriv här...</textarea><input type='hidden' name='receiveremail' value=<?php print $email;?>><input type='hidden' name='anvandarnamn' value=<?php print $myusername;?>><br><input id='submit' type='submit' name='submit' value='Skicka!'></form><div style='position:absolute; top: 0px; right:10px'><button type='button' onclick='avbryt()'>Avbryt</button></div>");

}
    function avbryt()
{
document.getElementById("demo").innerHTML=("");
}

    </script>

</head>
<body>

<div id="showProfileStyleID"><div class="showProfileStyle">
    <div class="bigsquare" style=" top: 0px; left: 0px; margin-left: 0px; margin-top: -1px" >

        <div class ="personalInfo" style='top: 10px; right:  120px;'>
        <h3><?php echo"Välkommen till $fornamn&nbsp;$efternamn's&nbsp;sida"; ?></h3>
        <br>
        <u><b>Personlig information:</b></u>
        <br><br>
      <?php if ($showEmail == yes)  {print "<p><b>Email:</b>&nbsp;$email </p>"; } ?>
        <p><b>Bor&nbsp;i:&nbsp;</b><?php echo "&nbsp;$stad&nbsp;,&nbsp;$lan"; ?></p>
      <?php if ($showPhone == yes)  {print "<p><b>Telefonnummer:</b>&nbsp;$telefon </p>"; } ?>
        </div></div>

                <div class="bigsquare" style=" top: 0px; left: 604px; margin-left: 0px; margin-top: -1px" >

<?php
    if ($myusername!=$_SESSION['myusername']){
    print "
        <div style='position : absolute; top:10px; left:10px; z-index:10;'>
	<button type='button' onclick='displayDate()'>Skicka meddelande till $myusername</button>
        <p id='demo'></p></div>";
         }
         else{
          echo  '<div class ="personalInfo" style = "top: 10px; right:  120px;"><h3>Redigera&nbsp;din&nbsp;profil</h3>';
          echo  "<a href='", '../InsertUser/changeDeleteProfileForm.php', '?userName=' . $myusername . '&action=1'."'>Redigera&nbsp;personuppgifter<br></a>";
          echo  "<a href='", '../InsertUser/changeDeleteProfileForm.php', '?userName=' . $myusername . '&action=2'."'>Byt&nbsp;lösenord<br></a>";
          echo  "<a href='", '../InsertUser/changeDeleteProfileForm.php', '?userName=' . $myusername . '&action=3'.'&picUrl='.$profilepicture."'>Byt&nbsp;profilbild<br></a>";
          echo '<br><br><br></div>';
         }
    
    $mailcheck = $_GET['cmejl'];
    if ($mailcheck==1){Print "<div style='position: absolute; top:40px; left:10px;'>Ditt meddelande har skickats till $myusername!</div>";}
    if ($mailcheck==2){Print "<div style='position: absolute; top:40px; left:10px;'>Det gick inte att skicka meddelande till $myusername</div>";}

        ?>
</div>

        <div class="pictureSquare" style=" z-index: 1;  top: 0px; left: 303px; margin-left: -1px; margin-top: -1px" >
        <center><h1><?php echo $myusername; ?></h1>
            <div class ="frame" style ="width: <?php print "$newSizearray0"?>; height: <?php print"$newSizearray1" ?> ;">
            <br><img src ="../Images/profilePictures/<?php echo $profilepicture;  ?>"<?php echo $newSize;  ?></div></center>
            

        
       
        </div>

<!--        Information squares-->
<!--        <div class="bigsquare" style=" top: 0px; left: 0px; margin-left: 0px; margin-top: -1px" ></div>-->
<!--        <div class="bigsquare" style=" top: 0px; left: 604px; margin-left: 0px; margin-top: -1px" ></div>-->

                    <h2>&nbsp;Fler&nbsp;verk&nbsp;av&nbsp;samma&nbsp;konstnär:</h2>

<?php
print "<center> <div id='showProfileStyleID'> <div class='showProfileStyle>";

include '../phpFunctions/getSinglePictureUrl.php';
     $i = 0;
     $top = 100;
     $left = 0;
     $marginLeft = 0;
     $marginTop = 340;
     $squaresPerRow = 6;
     $numberOfSquares = count($pictureURLArray);
     $squareHeight = 170; //Don't forget to change height and width in the CSS file to
     $squareWidth = 150;
     $picIndex = $itemIdArray;
     $totalNumberOfItems = count($picIndex);
     $hooverBlack ="thin solid #666666";
     $hooverGrey  ='thin solid #cecece';
     $itemID = $pictureURLArray[1];
     $urls ='../Bildgalleri/showItem.php';
     

 while($i  <$numberOfSquares && $i < $squaresPerRow) {

            $picURL = getSinglePictureUrl($picIndex[$i + $currentPage]);//Adding currentPage beacause we want to show next window of items
            $itemPrice = getItemPrice($picIndex[$i + $currentPage]);
            $itemSize = getItemSize($picIndex[$i + $currentPage]);

            if ($marginLeft > $squaresPerRow) {$top = $top+$squareHeight;
                                              ++$marginTop;
                                              $left = 0;
                                              $marginLeft=0;
                                              }


            echo  "<a href='", $urls, '?itemID=' . $picIndex[$i + $currentPage] . "'>";
            ////Unique url for each Item, the itemID i sent to that url with the $_GET function and information about that specific item can be obtained from the database

            print "<div class='square' style='top:$top";
            print "px; left: $left";
            print "px; margin-left: $marginLeft";
            print "px; margin-top: $marginTop";
            print "px;'";

            print "onmouseover='this.style.border=$hooverBlack;' onmouseout='this.style.border=$hooverGrey;'";

            print">";
            if ($picURL != NULL){
            print "<br><img src='../Bildgalleri/Paintings/$picURL' width='80' height='80'>
                   <br><p>Pris: $itemPrice kr</p>
                   <p>Storlek: $itemSize</p>";
             }
            print"</div></a>";

            ++$picIndex;
            ++$marginLeft;
            ++$i;
            $left = $left +$squareWidth;}
            print "</center></body></html>";

//            include '../Banner/sidfot.php';
 ?>





<div style ="position: absolute; top: 420px; right: 5px;">
 <?php

//Creating the browsefunction to browse through slides of art
$nextPage = $currentPage +6;
$previousPage = $currentPage -6;

if ($previousPage >= 0) {
echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $previousPage . '&profileName='. $myusername.'">Föregående sida </a> | ';
//If this link is pressed, $currentPage gets the value of $previousPage which result in that
//the previous Items from the databse is displayed
}
if ($nextPage < $totalNumberOfItems) {
echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $nextPage . '&profileName='.$myusername. '">Nästa sida</a>';
}
//print "$nextPage< $totalNumberOfItems " ;
//End of browsefunction
?>
</div>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br> 
<?php include '../Banner/sidfot.php'; ?>
